home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9203.ZIP / OOPASM.ZIP / MEMMNGR.ASM < prev    next >
Assembly Source File  |  1990-06-10  |  2KB  |  89 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8. IF1
  9.     INCLUDE    macros.mac
  10.     INCLUDE    objects.mac
  11. ENDIF
  12.  
  13.     EXTRN    sendMsg:NEAR
  14.  
  15.     EXTRN    DosError:WORD
  16.     EXTRN    Self:WORD
  17.  
  18.     .CODE
  19.  
  20. IF Dbug
  21.     PUBLIC    allocMem
  22. ENDIF
  23. COMMENT    %
  24. ==============================================================================
  25. Allocates a block of memory.
  26.  
  27. =============================================================================%
  28. allocMem    PROC    NEAR
  29.     getInst        bx,MemSize,Self        ;Get number of paras to alloc
  30.     setInst        MemSeg,Nil,,2        ;Clear memory segment
  31.     mov        ah,48h            ;DOS service number
  32.     int        DosInt            ;DOS interrupt
  33.     jc        alm1            ;Jump if dosErr
  34.     setInst        MemSeg,ax        ;Save seg addr
  35.     jmp        alm2            ;Exit
  36.  
  37. alm1:    send        DosError,Error,ax    ;Handle error
  38. alm2:    ret
  39. allocMem    ENDP
  40.  
  41.  
  42.  
  43. IF Dbug
  44.     PUBLIC    freeMem
  45. ENDIF
  46. COMMENT    %
  47. ==============================================================================
  48. Frees previously allocated memory block.
  49.  
  50. =============================================================================%
  51. freeMem    PROC    NEAR
  52.     getInst        ax,MemSeg,Self        ;Get seg addr of allocted mem
  53.     null        ax,frm2            ;Already freed? - Exit
  54.  
  55.     push        es
  56.     mov        es,ax            ;Set segment register
  57.     mov        ah,49h            ;DOS service number
  58.     int        DosInt            ;DOS interrupt
  59.     pop        es
  60.     jc        frm1            ;Jump if dosErr
  61.  
  62.     setInst        MemSeg,Nil,,2        ;Clear memory segment
  63.     jmp        frm2            ;Exit
  64.  
  65. frm1:    send        DosError,Error,ax    ;Handle error
  66. frm2:    ret
  67. freeMem    ENDP
  68.  
  69.  
  70.  
  71.     .DATA
  72.  
  73. defMsg    MemMngr,\
  74.     Open,\
  75.     <allocMem,,>
  76.  
  77. defMsg    MemMngr,\
  78.     Close,\
  79.     <,,freeMem>
  80.  
  81. defObj    MemMngr,\
  82.     <>,\
  83.     <>,\
  84.     <Open,Close>
  85.  
  86.  
  87.  
  88.     END
  89.